package com.yonder.controller;


import org.springframework.ui.Model;
import com.yonder.pojo.Items;
import com.yonder.service.ItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/items")

public class ItemsController {
    @Autowired
    private ItemsService itemsService;
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Items> items = itemsService.findAll();
        model.addAttribute("items",items);
        return "items";
    }

    @RequestMapping("/save")
    public String addItems( Items items){
        itemsService.addItems(items);
        return "redirect:/items/findAll";
    }
}
